{% extends "base.html" %}
{% block title %}Aircraft{% endblock %}
{% block scripts %}
<script>
  $(document).ready(function() {
    $("#nav-aircraft").addClass("active");
    registerDeleteConfirmation('/aircraft');
  });
</script>
{% endblock scripts %}

{% block body %}
{{ util.modal_confirm() }}
<div class="row">
  <div class="container">
    {% if aircraft is defined %}
      <table class="table table-hover">
        </thead>
          <tr>
            <th>Registration</th>
            <th>Make</th>
            <th>Model</th>
            <th>Category</th>
            <th>Class</th>
            <th>Engine Type</th>
            <th># Engines</th>
            <th>Tailwheel?</th>
            <th>High Performance?</th>
            <th>Retractable Gear?</th>
            <th>Has Flaps?</th>
          </tr>
        </thead>
        {% for a in aircraft %}
        <tr id="{{ a.key.urlsafe() }}">
          <td>{{ a.registration }}</td>
          <td>{{ a.make }}</td>
          <td>{{ a.model }}</td>
          <td>{{ a.category }}</td>
          <td>{{ a.aircraft_class }}</td>
          <td>{{ a.engine_type }}</td>
          <td>{{ a.num_engines }}</td>
          <td>
            <input type="checkbox" disabled=disabled {{ "checked=checked" if a.tailwheel }}>
          </td>
          <td>
            <input type="checkbox" disabled=disabled {{ "checked=checked" if a.high_performance }}>
          </td>
          <td>
            <input type="checkbox" disabled=disabled {{ "checked=checked" if a.retractable_gear }}>
          </td>
          <td>
            <input type="checkbox" disabled=disabled {{ "checked=checked" if a.has_flaps }}>
          </td>
          <td>
            <a href="/aircraft?aircraft={{ a.key.urlsafe() }}" class="btn btn-primary">Edit</a>
          </td>
          <td>
            <button type="button" value="{{ a.key.urlsafe() }}" class="btn delete">
              <span class="glyphicon glyphicon-trash"></span>
            </button>
          </td>
        </tr>
        {% endfor %}
      </table>
      {{ util.pager('/aircraft', prev_page, next_page) }}
    {% else %}
      <p>No aircraft are defined. Add some using the form below.</p>
    {% endif %}
  </div><!-- .container -->
</div><!-- .row -->
<div class="row">
  <div class="container well">
    <div class="col-lg-6">
    {% if edit_aircraft is defined %}
    <legend>Edit aircraft</legend>
    {% else %}
    <legend>Add a new aircraft</legend>
    {% endif %}
    <form method="post" action="/aircraft" class="form-horizontal">
      {% if edit_aircraft is defined %}
      <input type="hidden" name="aircraft" value="{{ edit_aircraft.key.urlsafe() }}">
      {% endif %}
      <div class="form-group">
        <label for="aircraft-registration" class="control-label col-lg-2">Registration</label>
        <div class="col-lg-10">
          <input type="text" class="form-control" name="registration" id="aircraft-registration" value="{{ edit_aircraft.registration if edit_aircraft is defined }}">
        </div>
      </div>
      <div class="form-group">
        <label for="aircraft-make" class="control-label col-lg-2">Make</label>
        <div class="col-lg-10">
          <input type="text" class="form-control" name="make" id="aircraft-make" value="{{ edit_aircraft.make if edit_aircraft is defined and edit_aircraft.make }}">
        </div>
      </div>
      <div class="form-group">
        <label for="aircraft-model" class="control-label col-lg-2">Model</label>
        <div class="col-lg-10">
          <input type="text" class="form-control" name="model" id="aircraft-model" value="{{ edit_aircraft.model if edit_aircraft is defined and edit_aircraft.model }}">
        </div>
      </div>
      <div class="form-group">
        <label for="aircraft-category" class="control-label col-lg-2">Category</label>
        <div class="col-lg-10">
          <select id="aircraft-category" class="form-control" name="category">
            {% for category in aircraft_categories %}
            <option>{{ category }}</option>
            {% endfor %}
          </select>
        </div>
      </div>
      <div class="form-group">
        <label for="aircraft-class" class="control-label col-lg-2">Class</label>
        <div class="col-lg-10">
          <select id="aircraft-class" class="form-control" name="aircraft_class">
            {% for class in aircraft_classes %}
            <option>{{ class }}</option>
            {% endfor %}
          </select>
        </div>
      </div>
      <div class="form-group">
        <label for="aircraft-engine-type" class="control-label col-lg-2">Engine Type</label>
        <div class="col-lg-10">
          <select id="aircraft-engine-type" class="form-control" name="engine_type">
            {% for engine in engine_types %}
            <option>{{ engine }}</option>
            {% endfor %}
          </select>
        </div>
      </div>
      <div class="form-group">
        <label for="aircraft-num-engines" class="control-label col-lg-2">Num Engines</label>
        <div class="col-lg-10">
          <select id="aircraft-num-engines" class="form-control" name="num_engines">
          {% for num in [1, 2, 3, 4] %}
            <option>{{ num }}</option>
          {% endfor %}  
          </select>
        </div>
      </div>
      <div class="form-group">
        <div class="col-lg-offset-2 col-lg-10">
          <div class="checkbox">
            <label>
              <input type="checkbox" checked="checked" name="has_flaps" value="has_flaps">Has Flaps?
            </label>
          </div>
        </div>
      </div>
      <div class="form-group">
        <div class="col-lg-offset-4 col-lg-8">
          <div class="checkbox">
            <label>
              <input type="checkbox" name="tailwheel" value="tailwheel">Tailwheel?
            </label>
          </div>
        </div>
      </div>
      <div class="form-group">
        <div class="col-lg-offset-2 col-lg-10">
          <div class="checkbox">
            <label>
              <input type="checkbox" name="retractable_gear" value="retractable_gear">Retractable Gear?
            </label>
          </div>
        </div>
      </div>
      <div class="form-group">
        <div class="col-lg-offset-2 col-lg-10">
          <div class="checkbox">
            <label>
              <input type="checkbox" name="controllable_prop" value="controllable_prop">Controllable Pitch Prop?
            </label>
          </div>
        </div>
      </div>
      <div class="form-group">
        <div class="col-lg-offset-2 col-lg-10">
          <div class="checkbox">
            <label>
              <input type="checkbox" name="high_performance" value="high_performance">High Performance?
            </label>
          </div>
        </div>
      </div>
      <div class="form-group">
        <div class="col-lg-offset-2 col-lg-10">
          {% if edit_aircraft is defined %}
          <button type="submit" class="btn btn-primary" name="save" value=1>Save</button>
          {% else %}
          <button type="submit" class="btn btn-primary" name="add" value=1>Add</button>
          {% endif %}
        </div>
      </div>
    </form>
  </div>
  </div><!-- Add aircraft container -->
</div><!-- Add aircraft row -->
{% endblock body %}
